<?php
namespace api\web\controller;
use api\web\model\NewsModel;
use cmf\controller\RestBaseController;

class NewsController extends RestBaseController
{
    public function index()
    {
        $key = input('get.key');
        $where = [];
        if ($key) {
            $where[] = ['title|author', 'like', '%' . $key . '%'];
        }
        //页码
        $page = input('page/d',1);
        //每页返回的条数
        $pageSize = input('page_size/d',10);
        $list = NewsModel::where($where)
            ->order('list_order','desc')
            ->field('id,title,image,create_time,abs')
            ->page($page,$pageSize)
            ->select();
        $this->success('新闻公告表', $list);
    }

    public function getNews()
    {
        $id = input('id/d');
        if(empty($id)){
            $this->error('查询失败');
        }
        $new = NewsModel::find($id);
        $content = $new['content'];
        $content1 = htmlspecialchars_decode($content);
        $content2 = cmf_replace_content_file_url($content1, true);
        $new['content'] = $content2;
        $this->success('新闻公告表', $new);
    }
}
